package util;

import java.io.IOException;

import models.Entity;

import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.JsonSerializer;
import org.codehaus.jackson.map.SerializerProvider;

public class JustIdSerializer<K> extends JsonSerializer<Entity<K>> {

	@Override
	public void serialize(Entity<K> entity, JsonGenerator jsonGenerator,
			SerializerProvider arg2) throws IOException,
			JsonProcessingException {

		jsonGenerator.writeStartObject();
		K k = entity.getId();
		if (k instanceof Long) {
			jsonGenerator.writeNumberField("id", (Long) k);
		} else {
			jsonGenerator.writeObjectField("id", k);
		}

		jsonGenerator.writeEndObject();

	}
}
